from django.db import models
from utils.mybase_model import Base


# Create your models here.

class Category(Base):  #课程分类表
    title = models.CharField(max_length=64)
    sequence = models.IntegerField(null=True)  # 展示顺序

    class Meta:
        db_table = "tb_category"


class Tag(Base):  # 标签表
    title = models.CharField(max_length=64)

    class Meta:
        db_table = "tb_tag"


class Course(Base):  #课程表
    title = models.CharField(max_length=64)
    desc = models.CharField(max_length=256, null=True)
    img = models.ImageField(upload_to='imgs/', null=True)
    category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
    tag = models.ForeignKey(Tag, models.SET_NULL, null=True)
    stage = models.ManyToManyField('app_path.Stage')  #阶段对应id
    status = models.IntegerField(default=0)  # (已上线, 即将上线, 下架)
    follow_num = models.IntegerField(default=0)

    class Meta:
        db_table = "tb_course"


class Chapter(Base):  # 章表
    title = models.CharField(max_length=64)
    chapter_id = models.IntegerField()
    course = models.ForeignKey(Course, on_delete=models.SET_NULL, null=True)

    class Meta:
        db_table = "tb_chapter"


class Knob(Base):  # 节表
    title = models.CharField(max_length=64)
    knob_id = models.IntegerField()
    chapter = models.ForeignKey(Chapter, on_delete=models.SET_NULL, null=True)

    class Meta:
        db_table = "tb_knob"


class Attention(Base):  # 关注表
    user = models.ForeignKey('user.User', on_delete=models.CASCADE, null=True)
    course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "tb_attention"


class MyCourse(Base):  # 我的课程
    user = models.ForeignKey('user.User', on_delete=models.CASCADE, null=True)
    course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "tb_mycourse"
